/**
 * @class ConceptGridPanel
 * @extends Ext.grid.GridPanel
 * @description 用户权限表格
 */
ConceptGridPanel = Ext.extend(Ext.grid.GridPanel, {

    myid : "my_id_concept",
    addWin : null, // 参数,AddMeshWindow
    editWin : null, // 参数,EditMeshWindow

    /**
     * 构造方法
     */
    constructor : function(_cfg) {

        if (_cfg == null) {
            _cfg = {};
        }

        Ext.apply(this, _cfg);
        // 实例化AddConceptWindow并将引用附加给当前属性addWin
        this.addWin = new AddConceptWindow();
        // 实例化EditConceptWindow并将引用附加给当前属性editWin
        this.editWin = new EditConceptWindow();

        // 数据存贮器
        this["store"] = new Ext.data.JsonStore({
            /*  url : "adminPermission.action?action=jsonList",*/
            /*  autoDestroy: true,*/
            remoteSort:true,
            totalProperty : 'total',
            root : 'rows',

            fields: [
                'semantictypenames','casn1name','registrynumber','dname','cui','semantictypeuis',
                'scopenote','preferredyn','crelation1ui','id','crelation2ui','crelationname',
                'dui','cumlsui','relatedregistrynumber','cname'
            ] ,

            proxy: new Ext.data.HttpProxy({
                //url: 'http://168.160.111.203:8080/mds/temp/5.json'
                url: 'concept.action'
            })
            ,
            baseParams:{
                action:"jsonList"
            }
        });

        /**
         * 拷贝父类的构造方法
         */
        ConceptGridPanel.superclass.constructor.call(this, {
            id : this.myid,
            title:"概念词列表",
            border:false,
            stripeRows:true, //交替行效果
            iconCls:"houfei-treeNodeLeafIcon",
            /* viewConfig : {
             autoFill : true, //自动填充
             forceFit : true
             },*/

            colModel : new Ext.grid.ColumnModel([
                // 复选框列
                new Ext.grid.CheckboxSelectionModel({
                    // 头

                    header : ""

                }),
                {id: 'id', header: "ID",dataIndex: 'id',width: 50,sortable: true},
                {header: "主题UI号",dataIndex: 'dui',width: 80,sortable: true},
                {header: "主题词",dataIndex: 'dname', width: 80, sortable: true },
                {id: 'name', header: "概念词是否作为优选主题词",dataIndex: 'preferredyn',width: 80,/* renderer: renderTopic,*/sortable: true },
                {header: "概念UI号",dataIndex: 'cui', width: 200, hidden: false,sortable: true ,align: 'right'},
                {header: "概念名称",dataIndex: 'cname',width: 200, hidden: false,sortable: true }  ,
                {header: "概念在UML中的UI号",dataIndex: 'cumlsui', width: 200,hidden: false,sortable: true}  ,
                {header: "化学物质结构名称",dataIndex: 'cumlsui',width: 200,hidden: false,sortable: true} ,
                {header: "化学物质登记号",dataIndex: 'registrynumber', width: 200,hidden: false,sortable: true}   ,
                {header: "范畴注释",dataIndex: 'scopenote',width: 200, hidden: false,sortable: true} ,
                { header: "概念词与主题词的关系",dataIndex: 'crelationname',width: 200,hidden: false,sortable: true} ,
                {header: "优选概念词的UI号",dataIndex: 'crelation1ui', width: 200,hidden: false,sortable: true},
                {header: "其他概念词的UI号",dataIndex: 'crelation2ui',width: 200,hidden: false,sortable: true}  ,
                {header: "相关化学物质登记号",dataIndex: 'relatedregistrynumber',width: 200,hidden: false,sortable: true}   ,
                {header: "语义关系代码", dataIndex: 'semantictypeuis',width: 200, hidden: false,sortable: true}  ,
                {header: "语义关系描述", dataIndex: 'semantictypenames', width: 200,  hidden: false, sortable: true }

            ]),
            loadMask : {
                msg : "正在加载数据,请稍后..."
            },
            // 行选择模式
            /*  selModel : new Ext.grid.RowSelectionModel({
             // 单行选择模式
             singleSelect : true
             }),*/
            sm: new Ext.grid.RowSelectionModel({singleSelect:true}),

            tbar : [
                {
                    text : "新建",
                    handler : this.onAddRole, // 添加角色事件
                    iconCls : "houfei-addicon", // 按钮图片样式
                    tooltip : "添加一个新的概念词信息", // 提示信息
                    scope : this
                    // 范围
                },
                "-",
                {
                    text : "编辑",
                    iconCls : "houfei-editicon",
                    handler : this.onEditRole, // 编辑角色事件
                    tooltip : "编辑概念词信息",
                    scope : this
                },
                "-",
                {
                    text : "刷新",
                    iconCls : "houfei-refreshIcon",
                    handler : this.onRefresh, // 刷新事件
                    tooltip : "刷新概念词信息",
                    scope : this
                }
                ,
                "-",
                {
                    text : "删除",
                    iconCls : "houfei-deleteIcon",
                    handler : this.onDelete, // 刷新事件
                    tooltip : "删除概念词信息",
                    scope : this
                } ,
                "-",
                {
                    text : "重新加载",
                    iconCls : "houfei-refreshIcon",
                    handler :function() {
                        this.getStore().baseParams.action = "jsonList";
                        this.getStore().baseParams.start = 0;
                        this.getStore().baseParams.limit = 17;
                        this.getStore().load();
                    }, // 刷新事件
                    tooltip : "重新加载概念词信息",
                    scope : this
                } ,
                "-",
                'Search: ',
                new ConceptAutoComplete({id:"search_ConceptList",width:250})
                ,
                {
                    text : "搜索",
                    iconCls : "houfei-searchIcon",
                    handler : this.onSearch, // 刷新事件
                    tooltip : "搜索概念词信息",
                    scope : this
                }
            ],
            bbar : new Ext.PagingToolbar({
                store : this["store"], // 数据存储器
                pageSize : 17, // 页大小
                displayMsg:"共<font color=\"green\"> {2} </font>条记录,当前页记录索引<font color=\"green\"> {0} - {1}</font>&nbsp;&nbsp;&nbsp;",
                displayInfo:true
            })
        });
        // 数据加载
        this.getStore().load({
            params : { // 参数
                start : 0, // 索引
                limit : 17
                // 页大小
            }
        });
    },
    /**
     *搜索
     */
    onSearch:function() {
        //alert(this.getStore().proxy.url = "r.action?action=search");

        this.getStore().baseParams.action = "search";
        this.getStore().baseParams.start = 0;
        this.getStore().baseParams.limit = 17;
        this.getStore().baseParams.highLight = 1
        this.getStore().baseParams.searchkey = Ext.getCmp("search_ConceptList").getValue();
        this.getStore().load();
        //alert(this.getStore().proxy.url);
    }    ,
    /**
     * 表格数据刷新
     */
    onRefresh : function() {
        this.getStore().reload();
    },

    onDelete:function() {
        var _sm = this.getSelectionModel();
        // 当用户选择了一条记录的时候将编辑窗口显示出来
        if (_sm.getCount() > 0) {
            Ext.Msg.confirm("系统消息", "您确定要删除当前行的Concept信息吗?",
                    this.onDeleteConfrimBtnClick, this);

        } else {
            Ext.Msg.show({
                title : "系统提示",
                msg : "请您选择一条您要删除的信息",
                buttons : Ext.Msg.OK,
                icon : Ext.Msg.INFO
            });
        }
    } ,
    /**
     * 提交Ajax请求成功事件
     *
     * @param {}
            *            _res
     */
    onSubmitSuccess : function(_res) {
        if (_res.responseText == "true") {
            Ext.Msg.alert("系统消息", "删除成功!");
            this.getStore().reload();
        } else {
            Ext.Msg.alert("系统消息", "操作失败,请检重新操作或与管理员联系!");
        }

    },

    /**
     * Ajax请求失败(连接失败)
     */
    onSubmitFailure : function() {
        Ext.Msg.alert("系统消息", "网络繁忙,请检查您的网络是否正常或与管理员联系!");
    },
    onDeleteConfrimBtnClick : function(_btn) {
        if (_btn == "yes") {
            // 获取当前表格的选择模式
            var _sm = this.getSelectionModel();
            // 获取当前表格主键id
            var _pkid = _sm.getSelected().get("id");
            // 进行异步Ajax请求
            Ext.Ajax.request({
                url : "concept.action",
                method : "post",
                success : this.onSubmitSuccess,
                failure : this.onSubmitFailure,
                scope : this,
                params : {
                    action : "delete",
                    id : _pkid
                }
            });
        }
    },
    /**
     * 添加分类词事件
     */
    onAddRole : function() {
        this.addWin.form.reset();
        this.addWin.show();
    },

    /**
     * 编辑分类词事件
     */
    onEditRole : function() {
        var _sm = this.getSelectionModel();
        // 当用户选择了一条记录的时候将编辑窗口显示出来
        if (_sm.getCount() > 0) {
            // 获取当前用户选择的记录
            var _r = _sm.getSelected();
            // 创建一个Record                    'rolename', 'permissions'

            var _rc = new Ext.data.Record({
                "semantictypenames":_r.get("semantictypenames"),"casn1name":_r.get("casn1name"),"registrynumber":_r.get("registrynumber"),"dname":_r.get("dname"),"cui":_r.get("cui"),"semantictypeuis":_r.get("semantictypeuis"),"scopenote":_r.get("scopenote"),"preferredyn":_r.get("preferredyn"),"crelation1ui":_r.get("crelation1ui"),"id":_r.get("id"),"crelation2ui":_r.get("crelation2ui"),"crelationname":_r.get("crelationname"),"dui":_r.get("dui"),"cumlsui":_r.get("cumlsui"),"relatedregistrynumber":_r.get("relatedregistrynumber"),"cname":_r.get("cname")
            });
            // 将窗体显示出来
            this.editWin.show();
            // 加载数据
            this.editWin.form.setFormValues(_rc);
            //alert(this.editWin.getForm().findField("semantictypenames"));
            //this.editWin.form.find("id").setDisabled(true);
            this.editWin.urId = _r.get("id");

        } else {
            Ext.Msg.show({
                title : "系统提示",
                msg : "请您选择一条您要修改的信息",
                buttons : Ext.Msg.OK,
                icon : Ext.Msg.INFO
            });
        }
    }

});